import requests

tieba_name = input("贴吧名：")
url_temp = "https://tieba.baidu.com/f?kw=" + tieba_name + "&ie=utf-8&pn={}"

# 准备url列表
url_list = [url_temp.format(i*50) for i in range(1000)]

# 发送请求，获取响应
headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"}
for url in url_list:
    resp = requests.get(url, headers=headers)

    # 保存
    file_path = "{}_第{}页.html".format(tieba_name, url_list.index(url)+1)

    with open(file_path, "w", encoding="utf-8") as f:
        f.write(resp.content.decode())
